/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * UltimatumDescriptionTextGUI.java
 *
 * Created on 15/Dez/2011, 19:00:07
 */

package intopo.game.impl.ultimatum;

import intopo.evogame.partnerselection.config.ParsingException;
import intopo.game.DescriptionGUI;
import intopo.game.DescriptionText;
import intopo.game.FoldStrategy;
import intopo.game.gui.AbstractGameEditorComponent;
import intopo.game.gui.AbstractStrategyEditorComponent;
import intopo.game.gui.AbstractGlobalParametersComponent;

import java.io.PrintStream;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author <a href="mailto:mariano.pedro@gmail.com">Pedro Mariano</a>
 *
 * @version 1.0 15/Dez/2011
 */
public class UltimatumDescriptionTextGUI
	implements
		DescriptionText<UltimatumGame, UltimatumStrategy>,
		DescriptionGUI<UltimatumGame, UltimatumStrategy>
{
	/**
	 * Sole instance of the game constructors that is returned by all instances of this class.
	 */
	static private Map<String, Constructor<? extends UltimatumGame>> gameConstructors;
	/**
	 * Sole instance of the strategy constructors that is returned by all instances of this class.
	 */
	static private Map<String, Constructor<? extends UltimatumStrategy>> strategyConstructors;
	/**
	 * 
	 */
	static private UltimatumGameComponent gameComponent;
	/**
	 *
	 */
	static private UltimatumStrategyComponent strategyComponent;
	/**
	 *
	 */
	static private UltimatumGlobalParametersComponent globalParametersComponent;
	static
	{
		// game constructors
		Constructor<UltimatumGame> cg;
		gameConstructors = new HashMap<String, Constructor<? extends UltimatumGame>> ();
		try {
			Class<UltimatumGame> c = UltimatumGame.class;
			cg = c.getConstructor (Scanner.class);
			gameConstructors.put (UltimatumGame.CONSTRUCTOR_TAG, cg);
		}
		catch (NoSuchMethodException nsme) {
			System.err.println ("Class UltimatumGame does not have a constructor with parameter type java.util.Scanner");
			System.exit (1);
		}
		// strategy constructors
		Constructor<? extends UltimatumStrategy> cp;
		strategyConstructors = new HashMap<String, Constructor<? extends UltimatumStrategy>> ();
		try {
			Class<UltimatumDeterministicStrategy> c = UltimatumDeterministicStrategy.class;
			cp = c.getConstructor (Scanner.class);
			strategyConstructors.put (UltimatumDeterministicStrategy.CONSTRUCTOR_TAG, cp);
		}
		catch (NoSuchMethodException nsme) {
			System.err.println ("Class UltimatumDeterministicStrategy does not have a constructor with parameter type java.util.Scanner");
			System.exit (1);
		}
		// swing components
		gameComponent = new UltimatumGameComponent ();
		strategyComponent = new UltimatumStrategyComponent ();
		globalParametersComponent = new UltimatumGlobalParametersComponent ();
	}
	/**
	 * 
	 */
	public UltimatumDescriptionTextGUI ()
	{

	}
	@Override
	public Map<String, Constructor<? extends UltimatumGame>> getGameConstructor ()
	{
		return gameConstructors;
	}

	@Override
	public Map<String, Constructor<? extends UltimatumStrategy>> getStrategyConstructors ()
	{
		return strategyConstructors;
	}

	@Override
	public void readGlobalParameters (Scanner scanner) throws ParsingException
	{
		UltimatumDeterministicStrategy.Parameters.read (scanner);
	}

	@Override
	public void writeGlobalParameters (PrintStream ps)
	{
		UltimatumDeterministicStrategy.Parameters.write (ps);
	}

	@Override
	public FoldStrategy<UltimatumStrategy> getFoldStrategy ()
	{
		throw new UnsupportedOperationException ("Not supported yet.");
	}

	@Override
	public String getBinDescription (Class<? extends UltimatumStrategy> c, int bin)
	{
		if (c.getCanonicalName ().equals ("intopo.game.impl.ultimatum.UltimatumDeterministicStrategy")) {
			return UltimatumDeterministicStrategy.getBinDescription (bin);
		}
		else {
			throw new Error ("Class " + c.getCanonicalName ()
				+ " does not have a bin description method or method getBinDescription() of class "
				+ this.getClass ().getCanonicalName () + " is not called in the description class");
		}
	}

	@Override
	public AbstractGameEditorComponent<UltimatumGame, UltimatumStrategy> getGameEditorComponent ()
	{
		return gameComponent;
	}

	@Override
	public AbstractStrategyEditorComponent<UltimatumStrategy> getStrategyEditorComponent ()
	{
		return strategyComponent;
	}

	@Override
	public AbstractGlobalParametersComponent getGlobalParametersEditorComponent ()
	{
		return globalParametersComponent;
	}

}

// Local Variables:
// mode: java
// mode: flyspell-prog
// ispell-local-dictionary: "british"
// End:
